package com.mine;

import java.util.concurrent.TimeUnit;

public class DeadLock {
    private static Object object1 = new Object();
    private static Object object2 = new Object();

    public static void main(String[] args) {
        new Thread(DeadLock::methodA).start();
        new Thread(DeadLock::methodB).start();
    }

    public static void methodA() {
        synchronized (object1) {
            System.out.println("methodA");
            try {
                TimeUnit.SECONDS.sleep(1);
                methodB();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public static void methodB() {
        synchronized (object2) {
            System.out.println("methodB");
            try {
                TimeUnit.SECONDS.sleep(1);
                methodA();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
